import { BaseScene } from './BaseScene'

export class HomeScene extends BaseScene {
  constructor(game) {
    super(game)
    this.buttons = {
      start: {
        x: this.width / 2 - 100,
        y: this.height / 2,
        width: 200,
        height: 50,
        text: '开始游戏'
      },
      history: {
        x: this.width / 2 - 100,
        y: this.height / 2 + 70,
        width: 200,
        height: 50,
        text: '历史记录'
      },
      ranking: {
        x: this.width / 2 - 100,
        y: this.height / 2 + 140,
        width: 200,
        height: 50,
        text: '排行榜'
      }
    }
  }
  
  init() {
    // 初始化触摸事件
    wx.onTouchStart(this.onTouchStart.bind(this))
  }
  
  render(ctx) {
    // 绘制背景
    ctx.fillStyle = '#f0f0f0'
    ctx.fillRect(0, 0, this.width, this.height)
    
    // 绘制标题
    ctx.fillStyle = '#333'
    ctx.font = 'bold 36px Arial'
    ctx.textAlign = 'center'
    ctx.fillText('真心话大冒险', this.width / 2, 100)
    
    // 绘制按钮
    Object.values(this.buttons).forEach(button => {
      // 按钮背景
      ctx.fillStyle = '#4ECDC4'
      ctx.fillRect(button.x, button.y, button.width, button.height)
      
      // 按钮文字
      ctx.fillStyle = '#fff'
      ctx.font = '24px Arial'
      ctx.textAlign = 'center'
      ctx.fillText(
        button.text,
        button.x + button.width / 2,
        button.y + button.height / 2 + 8
      )
    })
  }
  
  onTouchStart(e) {
    const touch = e.touches[0]
    const x = touch.clientX
    const y = touch.clientY
    
    // 检查按钮点击
    Object.entries(this.buttons).forEach(([key, button]) => {
      if (
        x >= button.x &&
        x <= button.x + button.width &&
        y >= button.y &&
        y <= button.y + button.height
      ) {
        switch (key) {
          case 'start':
            this.game.switchScene('lobby')
            break
          case 'history':
            // TODO: 显示历史记录
            break
          case 'ranking':
            // TODO: 显示排行榜
            break
        }
      }
    })
  }
} 